{{--@dd($model['fields'])--}}
@extends('content.layouts.default')
@section('content')
<div class="card">
    <div class="card-body">
        <ul class="nav nav-tabs nav-overflow header-tabs">
            <li class="nav-item">
                <a href="{{route('content.model.index')}}" class="nav-link pb-3 active">
                    模型列表
                </a>
            </li>
            <li class="nav-item">
                <a href="{{route('content.model.create')}}" class="nav-link pb-3">
                    新增模型
                </a>
            </li>
        </ul>
    </div>
    <div class="card-body small">
        <table class="table">
            <thead>
            <tr>
                <th>编号</th>
                <th>模型名称</th>
                <th>字段数量</th>
                <th>创建时间</th>
                <th></th>
            </tr>
            </thead>
            <tbody>
            @foreach($models as $model)
                <tr>
                    <td scope="row">{{$model['id']}}</td>
                    <td>{{$model['title']}}</td>
                    <td>{{count($model['fields'])}}</td>
                    <td>{{$model->created_at}}</td>
                    <td class="text-right">
                        @if($model['is_system'] == 0)
                        <div class="btn-group btn-group-sm" role="group" aria-label="First group">
                            <a href="{{route('content.model.edit',$model)}}" class="btn btn-light">编辑模型</a>
                            <button type="button" class="btn btn-white" onclick="del({{$model['id']}})">删除模型</button>
                            <form action="{{route('content.model.destroy',$model)}}" method="post" id="{{$model['id']}}">
                                @csrf @method('DELETE')
                            </form>
                        </div>
                            @endif
                    </td>
                </tr>
            @endforeach
            </tbody>
        </table>
    </div>
</div>
@endsection
@push('js')
    <script>
        function del(id) {
            if (confirm('确定删除吗？')) {
                $('#'+id).submit();
            }
        }
    </script>
    @endpush
